package com.party.controller;

import com.party.common.GlobleData;
import com.party.model.SysAreas;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 服务类 Controller
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: 12-3-1
 * Time: 下午3:10
 * To change this template use File | Settings | File Templates.
 */
@Controller
@RequestMapping(value = "/service")
public class ServiceController {

    /**
     * 获取省列表
     *
     * @param session
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/getProvinces", method = RequestMethod.GET)
    @ResponseBody
    public Map<String, Object> getProvinces(
            HttpSession session,
            HttpServletRequest request,
            HttpServletResponse response
    ) {
        List<SysAreas> provinces = GlobleData.provinceList;

        Map<String, Object> modelMap = new HashMap<String, Object>();
        modelMap.put("provinces", provinces);
        return modelMap;
    }


    /**
     * 根据省获取市级,二级联动
     *
     * @param provinceId 省id
     * @param session
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/getCitys", method = RequestMethod.GET)
    @ResponseBody
    public Map<String, Object> getCitys(
            @RequestParam("provinceId") String provinceId,
            HttpSession session,
            HttpServletRequest request,
            HttpServletResponse response
    ) {
        List<SysAreas> citys = GlobleData.cityMap.get(new Integer(provinceId));
        Map<String, Object> modelMap = new HashMap<String, Object>();
        modelMap.put("citys", citys);
        return modelMap;
    }


}
